package com.resign.carl.iterator.api.impl;

import java.util.Iterator;

import com.resign.carl.iterator.api.Menu;
import com.resign.carl.iterator.entity.MenuItem;

/**
 * Created by carl.zhao on 2016/6/16.
 */
public class DinerMenu implements Menu<MenuItem> {

    private static final int MAX_ITEMS = 6;
    private int numberOfItem = 0;
    MenuItem[] menuItems;

    public DinerMenu(){
        menuItems =  new MenuItem[MAX_ITEMS];
        addItem("haha", "haha", true, 2.99);
        addItem("hoho", "hoho", true, 3.99);
        addItem("hehe", "hehe", true, 3.29);
        addItem("xixi", "xixi", true, 1.99);
        addItem("xoxo", "xoxo", true, 1.38);
        addItem("xexe", "xexe", true, 5.01);
    }

    public Iterator<MenuItem> createIterator(){
        return new DinerMenuIterator(menuItems);
    }

    private void addItem(String name, String desc, boolean vegetarian, double price){
        if(numberOfItem >= MAX_ITEMS){
            System.out.println("Sorry, menu is full! Can't add item to menu");
        } else {
            MenuItem menuItem = new MenuItem(name, desc, vegetarian, price);
            menuItems[numberOfItem] = menuItem;
            numberOfItem++;
        }
    }
}
